<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdatetimepicker.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class timely_report2 extends Page
{
       public $Label4 = null;
       public $Label5 = null;
       public $Label6 = null;
       public $dateTo = null;
       public $dateFrom = null;
       public $Label2 = null;
       public $lblPlate = null;
       public $Image2 = null;
       public $btnDownload = null;
       public $lblmodel = null;
       public $lblmake = null;
       public $lblyr = null;
       public $Label43 = null;
       public $Label38 = null;
       public $lblyear = null;
       public $Label48 = null;
       public $lblVeh = null;
       public $Image1 = null;
       public $hiddenVeh = null;
       public $btnYearly = null;
       public $btnMonthly = null;
       public $btnDaily = null;
       public $JTSiteTheme1 = null;

       function timely_report2JSLoad($sender, $params)
       {
       //js can't modify visibility of elements that are declared
       //visible false using delphi property
       ?>
       var cal_field = document.getElementById('f-calendar-field-1');
       var cal_trigger = document.getElementById('f-calendar-trigger-1');
       var cmbyear = document.getElementById('cmbyear');
       var cmbmonth = document.getElementById('cmbmonth');
       var cmbyearly = document.getElementById('cmbyearly');

       cal_field.style.visibility = 'visible';
       cal_trigger.style.visibility = 'visible';
       cmbyear.style.visibility = 'hidden';
       cmbmonth.style.visibility = 'hidden';
       cmbyearly.style.visibility = 'hidden';
       <?php

       }

       function cmbReportTypeJSChange($sender, $params)
       {
       ?>
       var cal_field = document.getElementById('f-calendar-field-1');
       var cal_trigger = document.getElementById('f-calendar-trigger-1');
       var cmbyear1 = document.getElementById('cmbyear_outer');
       var cmbmonth1 = document.getElementById('cmbmonth_outer');
       var cmbyearly1 = document.getElementById('cmbyearly_outer');
       var cmbyear = document.getElementById('cmbyear');
       var cmbmonth = document.getElementById('cmbmonth');
       var cmbyearly = document.getElementById('cmbyearly');
       var date = document.getElementById('JTDateReport');

       var dropdown = document.getElementById('cmbReportType');
       var indexval = dropdown.value;

       if(indexval=='1')
       {
        cal_field.style.visibility = 'visible';
        cal_trigger.style.visibility = 'visible';
        cmbyear.style.visibility = 'hidden';
        cmbmonth.style.visibility = 'hidden';
        cmbyearly.style.visibility = 'hidden';
        cmbyear1.style.left = '220px';
        cmbmonth1.style.left = '320px';
        cmbyearly1.style.left = '220px';
       }
       if(indexval=='2')
       {
        cal_field.style.visibility = 'hidden';
        cal_trigger.style.visibility = 'hidden';
        cmbyear.style.visibility = 'visible';
        cmbmonth.style.visibility = 'visible';
        cmbyearly.style.visibility = 'hidden';
        cmbyear1.style.left = '12px';
        cmbmonth1.style.left = '112px';
        cmbyearly1.style.left = '220px';
       }
       if(indexval=='3')
       {
        cal_field.style.visibility = 'hidden';
        cal_trigger.style.visibility = 'hidden';
        cmbyear.style.visibility = 'hidden';
        cmbmonth.style.visibility = 'hidden';
        cmbyearly.style.visibility = 'visible';
        cmbyear1.style.left = '220px';
        cmbmonth1.style.left = '320px';
        cmbyearly1.style.left = '12px';
       }
       <?php

       }

       function btnDownloadClick($sender, $params)
       {
        /*
        $type = $this->cmbReportType->getItemIndex();
        if($type=='1')
        {
         $daily = $this->JTDateReport->getText().'%';
         redirect('veh_reports.php?report_date='.$daily.'&veh='.$this->hiddenVeh->getValue().'&type=d');
        }
        if($type=='2')
        {
         $monthly = $this->cmbyear->getItemIndex().'-'.$this->cmbmonth->getItemIndex().'-%';
         redirect('veh_reports.php?report_date='.$monthly.'&veh='.$this->hiddenVeh->getValue().'&type=m');
        }
        if($type=='3')
        {
         $yearly = $this->cmbyearly->getItemIndex().'-%'.'-%';
         redirect('veh_reports.php?report_date='.$yearly.'&veh='.$this->hiddenVeh->getValue().'&type=y');
        }
        */
        $date_from = $this->dateFrom->getText();
        $date_to = $this->dateTo->getText();
        redirect('veh_reports2.php?hfDateFrom='.$date_from.'&hfDateTo='.$date_to.'&hfAllOrSelect='.$this->hiddenVeh->getValue());

       }

       function cmbReportTypeChange()
       {
        $type = $this->cmbReportType->getItemIndex();
        if($type=='1')
        {
         $this->JTDateReport->Visible=true;
         $this->cmbyear->setVisible(false);
         $this->cmbmonth->setVisible(false);
         $this->cmbyearly->setVisible(false);
        }
        if($type=='2')
        {
         $this->JTDateReport->Visible=false;
         $this->cmbyear->setVisible(true);
         $this->cmbmonth->setVisible(true);
         $this->cmbyearly->setVisible(false);
        }
        if($type=='3')
        {
         $this->JTDateReport->Visible=false;
         $this->cmbyear->setVisible(false);
         $this->cmbmonth->setVisible(false);
         $this->cmbyearly->setVisible(true);
        }

       }

       function timely_report2Create($sender, $params)
       {
       $veh = $_GET['veh'];
       $xxx = $_GET['xxx'];
       if($veh!=null | $veh!='')
       $this->hiddenVeh->setValue(base64_decode($veh));

       /*echo "<script type=text/javascript>
       alert('".base64_decode($veh)."');
       alert('".base64_decode($xxx)."');
       </script>";*/

       //$this->JTDateReport->Text = (date('Y-m-d')); error: changed dateTimePicker to JTDateTimePicker

       $result_vin = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='".$this->hiddenVeh->getValue()."'")or die(mysql_error());
       $row_selected = mysql_fetch_array($result_vin);
       $label = $row_selected['VIN'];
       $this->lblPlate->Caption = $row_selected['veh_num'];
       $this->lblVeh->Caption = $label;
       $this->lblyr->Caption = $row_selected['year'];
       $this->lblmake->Caption = $row_selected['manufacturer_name'];
       $this->lblmodel->Caption = $row_selected['model_name'];

       $this->dateTo->Text = "";
       $this->dateFrom->Text = "";
       }

       function btnYearlyClick($sender, $params)
       {
       $yearly = $this->cmbyearly->getItemIndex().'-%'.'-%';
       redirect('veh_reports.php?report_date='.$yearly.'&veh='.$this->hiddenVeh->getValue().'&type=y.');
       }

       function btnMonthlyClick($sender, $params)
       {
       $monthly = $this->cmbyear->getItemIndex().'-'.$this->cmbmonth->getItemIndex().'-%';
       redirect('veh_reports.php?report_date='.$monthly.'&veh='.$this->hiddenVeh->getValue().'&type=m.');
       }

       function btnDailyClick($sender, $params)
       {
       $daily = $this->JTDateReport->getDate().'%';
       redirect('veh_reports.php?report_date='.$daily.'&veh='.$this->hiddenVeh->getValue().'&type=d.');
       }

}

global $application;

global $timely_report2;

//Creates the form
$timely_report2=new timely_report2($application);

//Read from resource file
$timely_report2->loadResource(__FILE__);

//Shows the form
$timely_report2->show();

?>